<?php

namespace App\Admin\Controllers;

use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use \App\Models\Brand;

class BrandsController extends AdminController
{
    protected $title = '品牌管理';
    
    protected function grid()
    {
        $grid = new Grid(new Brand());

	    $grid->disableExport();
	
	    $grid->column('id', 'ID');
	    $grid->column('name', '名称');
	    $grid->column('name_mini', '别名');
	    $grid->column('order', '排序');
	    $grid->column('created_at', '创建时间')->display(function () {
		    return $this->created_at->toDatetimeString();
	    });
	
	    $grid->disableRowSelector();

        return $grid;
    }
	
	protected function detail($id)
	{
		$show = new Show(Brand::findOrFail($id));
		
		$show->field('id', __('Id'));
		$show->field('name', __('Name'));
		$show->field('name_mini', __('Name mini'));
		$show->field('image', __('Image'));
		$show->field('order', __('Order'));
		$show->field('created_at', __('Created at'));
		$show->field('updated_at', __('Updated at'));
		
		return $show;
	}
    
    protected function form()
    {
        $form = new Form(new Brand());

	    $form->text('name', '品牌名称');
	    $form->text('name_mini', '品牌别名');
	    $form->image('image', '品牌图标')->uniqueName()->removable();
	    $form->text('order', '显示顺序')->default(1000);
	    $form->radio('is_shown', '显示')->default(true)->options(config('site.bool'));

        return $form;
    }
}
